//LiteLoaderScript Dev Helper
/// <reference path="e:\vsCodePlugins\mcide/Library/JS/Api.js" /> 

/**
 * 插件名:限制低体力挖掘
 */

mc.listen("onStartDestroyBlock", function (player,block) {//"onDestroyBlock"
    let nbts = player.getNbt();
    let Attributes = nbts.getTag('Attributes');
    let hungerNbt = Attributes.getData(9);//////饥饿值
    // log(hungerNbt.toSNBT());
    if(hungerNbt.getData('Current')<5){
        player.tell('你的体力不够,无法开采物资!',5);
        let plgameMode = player.gameMode;
        player.setGameMode(2);
        player.setGameMode(plgameMode);
        return false;
    }
});

mc.listen("onDestroyBlock", function (player,block) {
    let nbts = player.getNbt();
    let Attributes = nbts.getTag('Attributes');
    let hungerNbt = Attributes.getData(9);//////饥饿值
    // log(hungerNbt.toSNBT());
    if(hungerNbt.getData('Current')<5){
        return false;
    }
    hungerNbt.setFloat('Current',4);
    Attributes.setTag(9,hungerNbt);
    player.setNbt(nbts);
});


// {
//     "Base": 20,
//     "Current": 20,
//     "DefaultMax": 20,
//     "DefaultMin": 0,
//     "Max": 20,
//     "Min": 0,
//     "Name": "minecraft:player.hunger"
// }